<?php

if(!empty($_POST['username'])){
	// print_r($_POST);print_r($_SESSION);exit;
	if(!empty($_SESSION['Verify'])){
		if(strtolower($_SESSION['Verify'])!=strtolower($_POST['verify'])){
			echo "<script>alert('您输入的验证码不正确！');location='index.php?admin=1&c=admin&a=login';</script>";exit;
		};
		unset($_POST['verify']);
	};
$username=$_POST['username'];
$password=md5($_POST['password']);
$where="`username`='$username' and `password`='$password'";
$table='admin';
//$sql="select * from admin where `username`='$username' and `password`='$password'";
$row=getlist($table,$where);
	if(!empty($row)){
		
		$_SESSION['admin']=$row;
		
		if(!empty($_POST['remember'])){
		setcookie('username',"$username",time()+60*60*24,'/');
		setcookie('password',$_POST['password'],time()+60*60*24,'/');
		}else{
			setcookie('username','',0,'/');
			setcookie('password','',0,'/');
			};
		header('location:index.php?admin=1&c=news&a=list');
	
	}else{echo '<script>alert ("登录失败");location="index.php?admin=1&c=admin&a=login";</script>';};
};
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CMS后台管理-登录</title>
<link href="images/favicon.ico" rel="shortcut icon"/>
<link href="resource/css/share.css" rel="stylesheet" type="text/css"/>
<link href="resource/css/default/login.css" rel="stylesheet" type="text/css"  />
<link href="resource/css/default/share.css" rel="stylesheet" type="text/css"  />
<script src="share/js/jquery-1.11.0.js"></script>
<script src="resource/js/jquery-1.8.3.min.js" type="application/javascript"></script>
<script src="admin/js/login.js"></script>
</head>

<body id="loginBody">
<a href="index.php">首页</a>
<form  method="post" action="index.php?admin=1&c=admin&a=login">
<div id="pointerOpen" onclick="hideLoginBezel()">开启登录</div>
<div id="loginBezel">
<!-- <div id="loginChildTop" onclick="hideLoginBezel()" title="点击将隐藏登录小窗口">　CMS管理平台</div> -->
<div id="loginChildTop">　<img src="resource/images/logo-right.png" width="57" height="50" align="absbottom"  /> CMS管理平台</div>
<div id="loginChildBottom">
<table cellpadding="0" cellspacing="0" width="100%" height="95%" border="0">
<tr>
<td align="right" width="35%">账　号：</td>
<td align="left" width="65%"><input type="text" id="account" value="<?php if(!empty($_COOKIE['username'])) echo $_COOKIE['username'];?>"  class="inputUP" name="username"/></td>
</tr>
<tr>
<td align="right">密　码：</td>
<td align="left"><input type="password" id="pwd" value="<?php if(!empty($_COOKIE['password'])) echo $_COOKIE['password'];?>" class="inputUP" name="password"/></td>
</tr>
<tr>
<td align="right">验证码：</td>
<td align="left"><input type="text" name="verify" id="checkNum"/>&nbsp;<span id="checkNumResult"><img src="<?php echo VERIFY_PATH.'mvc/protected/model/verify.php';?>" class="verifyimg" id="checkImage" align="absbottom" alt="验证码" title="点击更换验证码" /></span></td>
</tr>
<tr align="right"><td><label><input name="remember" type="checkbox" <?php if(!empty($_COOKIE['password'])){echo  'checked="checked"';};?>/>记住密码</label></td></tr>
<tr>
<td align="center" colspan="2"><input type="submit" class="submit" onclick="toLogin(this)"  id="toLogin" value="登　录"/> </td>
</tr> 
</table>
</div>
</div>
</form>
</body>
</html>
<script>
	
	$('.verifyimg').click(function(){
       var src=$(this).attr('src');
       src=src.substr(0,52);
       src=src+='?p='+Math.random();
       $(this).attr('src',src);
    })
    $('.submit').click(function(){
       if($('#account').val().length=='0'){
       	alert('请输入用户名！');
       	return false; 
       };
       if($('#pwd').val().length=='0'){
       	alert('请输入密码！');
       	return false; 
       };
       if($('#checkNum').val().length=='0'){
       	alert('请输入验证码！');
       	return false; 
       };

    })

</script>